package com.android.lovely.ext

import android.app.Activity
import android.content.Context
import android.graphics.Color
import android.net.ConnectivityManager
import android.net.Network
import android.net.NetworkCapabilities
import android.os.Build
import android.provider.Settings
import android.text.format.DateUtils
import android.util.Log
import com.kotlin.extensions.appContext
import com.kotlin.extensions.context.ActivityExt.navBarColor
import com.kotlin.extensions.context.ActivityExt.navBarLightMode
import com.kotlin.extensions.context.ActivityExt.statusBarColor
import com.kotlin.extensions.context.ActivityExt.statusBarLightMode
import com.kotlin.extensions.context.ActivityExt.transparentNaviBar
import com.kotlin.extensions.context.ActivityExt.transparentStatusBar
import java.util.TimeZone

/**
 *
 * @author why
 * @date 2025/3/7 18:22
 */
fun isVPNConnected(): Boolean {
    val connectivityManager =
        appContext.getSystemService(Context.CONNECTIVITY_SERVICE) as? ConnectivityManager
    if (connectivityManager != null) {
        val networks: Array<Network> = connectivityManager.allNetworks
        for (network in networks) {
            val capabilities = connectivityManager.getNetworkCapabilities(network)
            if (capabilities != null && capabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN)) {
                return true
            }
        }
    }
    return false
}

val androidId: String by lazy {
    Settings.Secure.getString(appContext.contentResolver, Settings.Secure.ANDROID_ID).apply {
        Log.e("StoreManager", "Android Id = $this")
    }
}

fun getPhoneName(): String {
    val deviceName: String = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
        Settings.Global.getString(appContext.contentResolver, Settings.Global.DEVICE_NAME)
    } else {
        Settings.Secure.getString(appContext.contentResolver, "bluetooth_name") ?: Build.MODEL
    }
    return deviceName
}

fun getTimeZone(): String {
    return "GMT${(TimeZone.getDefault().rawOffset / DateUtils.HOUR_IN_MILLIS).let { if (it >= 0) "+$it" else "$it" }}"
}

fun Activity.fullScreen() {
    transparentStatusBar()
    statusBarLightMode = false

    transparentNaviBar()
    navBarLightMode = false

}